package com.sgy.springboot_demo.config;

public class RoutingDataSourceContext {

    static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    /*
    * key：指定数据源类型
    * */
    public RoutingDataSourceContext(String key) {
        threadLocal.set(key);
    }

    public static String getDataSourceRoutingKey() {
        return threadLocal.get() == null ? "master" : threadLocal.get();
    }

    public void close () {
        threadLocal.remove();
    }
}
